package com.dream.inspect.modules.business.controller;

import com.dream.inspect.common.utils.R;
import com.dream.inspect.common.utils.StringUtil;
import com.dream.inspect.modules.business.entity.SysXzqhEntity;
import com.dream.inspect.modules.business.service.SysXzqhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * 行政区划表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-06-16 17:04:57
 */
@RestController
@CrossOrigin
@RequestMapping("business/sysxzqh")
public class SysXzqhController {
    @Autowired
    private SysXzqhService sysXzqhService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list() {
        List<SysXzqhEntity> list = sysXzqhService.findProvincesAndCities();

        return R.ok().put("list", list);
    }

    /**
     * 根据父id查询下级区划
     *
     * @param params
     * @return
     */
    @RequestMapping("/findXzqhByParentId")
    public R findXzqhByParentId(@RequestParam Map<String, Object> params) {
        String parentId = params.get("parentId") + "";
        if (StringUtil.isNotEmpty(parentId)) {
            List<SysXzqhEntity> list = sysXzqhService.findXzqhByParentId(Long.valueOf(parentId));
            return R.ok().put("list", list);
        }
        return R.error();
    }

}
